<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{$id}</title>
	<include file="Public:header" />
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerForm.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerDateEditor.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerComboBox.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerCheckBox.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerButton.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerRadio.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerSpinner.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerTextBox.js" type="text/javascript"></script> 
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerTip.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/jquery-validation/jquery.validate.min.js" type="text/javascript"></script> 
    <script src="__PUBLIC__/lib/jquery-validation/jquery.metadata.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/jquery-validation/messages_cn.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/jquery.form.js" type="text/javascript"></script> 
    <script type="text/javascript"> 
        var groupicon = "__PUBLIC__/lib/ligerUI/skins/icons/communication.gif";
        $(function ()
        {
            //创建表单结构
            var mainform = $("#detailform");
              mainform.ligerForm({
                inputWidth: 170, labelWidth: 90, space: 40,
                fields: [
                { name: "id", type: "hidden" },
                { display: "标识", name: "name", newline: true, type: "text", validate: { required: true,minlength:3 }, group: "基础信息", groupicon: groupicon}, 
                { display: "名称", name: "title", newline: true, type: "text", validate: { required: true,minlength:3 }},
                { display: "状态", name: "status", newline: true, type: "select", comboboxName: "Name1", options: {valueFieldID: "status",data:[{text:"启用",id:"1"},{text:"禁用",id:"0"}]}},
                { display: "显示", name: "show", newline: true, type: "select", comboboxName: "Name2", options: {valueFieldID: "show",data:[{text:"启用",id:"1"},{text:"禁用",id:"0"}]}}
                ]
            });
            var id={$id};
            if(id!=0){
                $.get('__URL__/getById/id/'+id,function(data){
                     var currentdata=jQuery.parseJSON(data);
                	 loadform(mainform,{},currentdata);
                 });
               
            }
            
        });
                 
        function loadform(mainform, options,data)
        {
        	var preID = options.preID || "";
            //根据返回的属性名，找到相应ID的表单元素，并赋值
           //$.ligerDialog.alert('选择的是' +data.name);
            for (var p in data)
            {
                var ele = $("[name=" + (preID + p) + "]", mainform);
               // alert(p);
                //针对复选框和单选框 处理
                if (ele.is(":checkbox,:radio"))
                {
                    ele[0].checked = data[p]==1 ? true : false;
                    //alert(data[p]);
                }
                else
                {
                    ele.val(data[p]);
                }
            }
            //下面是更新表单的样式
          var managers = $.ligerui.find($.ligerui.controls.Input);
            for (var i = 0, l = managers.length; i < l; i++)
            {
                //改变了表单的值，需要调用这个方法来更新ligerui样式
              var o = managers[i];
                o.updateStyle();
                if (managers[i] instanceof $.ligerui.controls.TextBox)
                    o.checkValue();
            }
        }//end function loadform
               
        function f_subset()
        {
            return $("#detailform").serialize();
          // return $("#detailform").formToArray()
        	// return $(":checkbox,:radio").serialize();
        }
        function f_save(){
          	 $.post("__URL__/edit/",$("#detailform").serialize(),function(data){
          		LG.showMessage(data, function () { 
        			window.parent.grid.loadData();
                    window.parent.mydialog.close(); //要先刷新表格,再关闭窗口,否则表格不会刷新 
                });
          	 });
           }
    </script> 

</head>
<body style="padding:10px"> 
    <form id="detailform">
    </form> 
 </body>
</html>